<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>show Result page</title>
    <c:import url="jsp/import.jsp"/>
    <script type="text/javascript" language="javascript"
            src="js/webSocket.js"></script>
    <script type="text/javascript">
        $(document).ready(
                function () {
                    var dataId = 'data_11111';
                    var host = '<c:out value="${pageContext.request.serverName}" />';
                    startWebSocketServer(host, dataId, defaultOnOpen, myMessageCall, defaultOnClose);

                });

        function sendMyMessage() {
            // 通过WebSocket想向服务器发送一个文本信息
            //ws.send("text123456789");
        }
        /**
         * 接收到服务器端消息后的回调函数
         */
        function myMessageCall(recv) {
            var data = eval('(' + recv.data + ')');
            var message = $("#showLogs").text() + "\n" + data.message;
            //日志只显示10000个字符
            var messLen = message.length;
            if (messLen > 10000) {
                message = message.substring(messLen - 10000, messLen);
            }

            $("#showLogs").text(message);

            if (data.complete && data.successfully) {
                window.location.href = "success.jsp";
            }
        }

        /**
         * 让输出日志的文本域滚动条在最下面
         */
        function autoScroll() {
            var t = $("#showLogs");
            t.scrollTop = t.scrollHeight;

        }

    </script>
</head>
<body>
<c:import url="jsp/header.jsp"/>
<div class="container">
    <div class="well">
        <div class="content">
            response:
            <!-- 任务日志信息-->
            <textarea class="areafield" id="showLogs" readonly="true"
                      placeholder="" value=""></textarea>
            <br/>
        </div>
    </div>
    <c:import url="jsp/footer.jsp"/>
</div>
</body>
</html>